<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>methods 实例</title>
    <script type="text/javascript" src="../assests/js/vue.js"></script>
</head>
<body>
    <h1> medthods传参&组件调用&外部调用</h1>
    <hr>
    <div id="app">
        {{ price }}
        <button @click="add(2,$event)">add</button>
        <btn name="xiaoming" @click.native="add(5)"></btn>
    </div>
    <button onclick="app.add()">ADD---作用于外部</button>
    <script>
        var app = new Vue({
            el:"#app",
            data:{
                price:0
            },
            components:{
                "btn":{
                    template:`<button>{{ btnName }} -- {{ name }}</button>`,
                    data:function(){
                        return {
                            "btnName":"ADD外部"
                        }
                    },
                    props:["name"]
                }
            },
            methods:{
                add:function(num,event){
                    if(num){
                        this.price += num;
                    }else{
                        this.price++;
                    }
                    if(arguments.length==2){
                        console.log(event);
                    }
                }
            }
        });
    </script>
</body>
</html>